<template>
  <a-card :bordered="false" class="card-area">
    <!-- 查询区域 11111-->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" :label-col="labelCol" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="5" :sm="8">
            <a-form-item label="状态">
              <a-select v-model="queryParam.status" placeholder="请选择状态">
                <a-select-option value="">请选择</a-select-option>
                <a-select-option value="0">无效</a-select-option>
                <a-select-option value="1">有效</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="8">
            <a-form-item label="销售类型">
              <a-select v-model="queryParam.saleType" placeholder="请选择销售类型">
                <a-select-option value="">请选择</a-select-option>
                <a-select-option value="0">线下</a-select-option>
                <a-select-option value="1">线上</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="菜品名称">
              <a-input placeholder="请输入菜品名称" v-model="queryParam.cpName"></a-input>
            </a-form-item>
          </a-col>
          <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
           <a-col :md="6" :sm="24">
               <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
               <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
           </a-col>
        </span>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="batchDown" type="primary" icon="plus">批量下架</a-button>
    </div>


    <!-- table区域-begin -->
    <div>


      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" v-if="record.status=='1'">设为下架</a>
          <a @click="handleEdit(record)" v-if="record.status=='0'">设为上架</a>
          <a-divider type="vertical" />
           <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
               <a>删除</a>
           </a-popconfirm>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <ordStoreCpRule-modal ref="modalForm" @ok="modalFormOk"></ordStoreCpRule-modal>
  </a-card>
</template>
<script>
import '@/assets/less/TableExpand.less'
import OrdStoreCpRuleModal from './modules/OrdStoreCpRuleModal'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { putAction, getAction, postAction } from '@/api/manage'
import { frozenBatch } from '@/api/api'

export default {
  name: 'ord_store_cp_ruleList',
  mixins: [JeecgListMixin],
  components: {
    OrdStoreCpRuleModal
  },
  data() {
    return {
      description: '门店菜品上架规则表管理页面',
      labelCol: { style: { width: '110px' } },
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '菜品名称',
          align: 'center',
          dataIndex: 'cpName'
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'status',
          customRender: function(t, r, index) {
            return t == '0' ? '已下架' : '已上架'
          }
        },
        {
          title: '销售类型',
          align: 'center',
          dataIndex: 'saleType',
          customRender: function(t, r, index) {
            return t == '0' ? '线下' : '线上'
          }
        },

        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/store/cpInfo/rule/list',
        delete: '/store/cpInfo/rule/delete',
        batchDown: '/ord/ordCpInfo/downBatch',
      }
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    batchDown: function() {
      if (!this.url.batchDown) {
        this.$message.error('请设置url.batchDown属性!')
        return
      }
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请选择一条记录！')
        return
      } else {
        var ids = ''
        for (var a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectedRowKeys[a] + ','
        }
        var that = this
        this.$confirm({
          title: '确认下架',
          content: '是否下架选中数据?',
          onOk: function() {
            that.loading = true
            deleteAction(that.url.batchDown, { ids: ids }).then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.loadData()
                that.onClearSelected()
              } else {
                that.$message.warning(res.message)
              }
            }).finally(() => {
              that.loading = false
            })
          }
        })
      }
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
